<template>
<el-main>
<el-row>
<el-col :span="20" :offset="1">
<el-tabs type="border-card">
<el-tab-pane label="修改密码">

<el-row >
    <el-col :span="8" :offset="5">
        <el-form :model="ruleForm" label-width="180px" class="demo-ruleForm" size="mini">
            <el-form-item label="旧密码" prop="opassword">
                <el-input type="password" v-model="ruleForm.opassword"></el-input>
            </el-form-item>
            <el-form-item label="新密码" prop="newpassword">
                <el-input type="password" v-model="ruleForm.newpassword" ></el-input>
            </el-form-item>
            <el-form-item label="再次输入新密码" prop="newpassword2">
                <el-input type="password" v-model="ruleForm.newpassword2"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm()">提交</el-button>
            </el-form-item>
        </el-form>
    </el-col>
</el-row>

    </el-tab-pane>
</el-tabs>
</el-col>
</el-row>
</el-main>
</template>
<script>
export default {
    data(){
        return {
            ruleForm:{
                
            }
        }
    },
    methods:{
        submitForm(){
                if(this.ruleForm.password === this.ruleForm.password2){
                    let json={
                        opwd:this.$md5(this.ruleForm.opassword),
                        npwd:this.$md5(this.ruleForm.newpassword)
                    }
                    let token=JSON.parse(this.$base64.decode(this.$cookies.get("token").split(".")[1]))
                    this.$http.Put(this.$api.pchange+"/"+token.userid,json,()=>{
                        this.$router.push({path:"/login"})
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            
        }
    }
    
}
</script>